package com.avic.rong.goodsSort.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.goodsSort.activity.secondListActivity.GoodsSortBzActivity;
import com.avic.rong.goodsSort.bean.GoodsSortItemBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Chenjiaxin on 2019/7/15 16:36
 * E-Mail Address：16601203965@163.com
 */
public class GoodsItemRvAdapter extends RecyclerView.Adapter<GoodsItemRvAdapter.GoodsItemRvViewHolder> {

    private Context context;
    private List<GoodsSortItemBean.InternalListBean> beanList;
    private int topType;

    public GoodsItemRvAdapter(Context context, List<GoodsSortItemBean.InternalListBean> list, int topType) {
        this.context = context;
        this.beanList = list;
        this.topType = topType;
    }

    @NonNull
    @Override
    public GoodsItemRvViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(R.layout.view_goods_rv_item, viewGroup, false);
        return new GoodsItemRvViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull GoodsItemRvViewHolder holder, int position) {

        GoodsSortItemBean.InternalListBean internalBean = beanList.get(position);
        holder.tv.setText(internalBean.getCatName());
        holder.itemView.setOnClickListener(new ItemClickListener(internalBean, topType));

    }

    public class ItemClickListener implements View.OnClickListener {

        GoodsSortItemBean.InternalListBean internalBean;
        int topType;

        public ItemClickListener(GoodsSortItemBean.InternalListBean internalBean, int topType) {
            this.internalBean = internalBean;
            this.topType = topType;
        }

        @Override
        public void onClick(View view) {
            context.startActivity(GoodsSortBzActivity.getIntent(context, topType, 0, String.valueOf(internalBean.getCatId()), null));
        }
    }


    @Override
    public int getItemCount() {
        return beanList.size();
    }

    class GoodsItemRvViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.goods_Item_tv)
        TextView tv;

        public GoodsItemRvViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
